s<template>
	<view class="contont">
		<view class="registered">
			<input type="text"  placeholder="请输入电话号码" v-model="temple"/>
		</view>
		<view class="registered" style="display: flex;">
			<input type="text"  placeholder="请输入验证码" v-model="codes" style="background-image: url(../../static/img/icon_yzm@2x.png); width: 250px;"/>
			<view class="yan" @click="add" v-show="Code">
				验证码
			</view>
			<view class="yan" v-show="Code==false" style="background-color: #C1C1C1;">
				{{second}}
			</view>
		</view>
		<button @click="reg" >下一步</button>
	</view>
</template>

<script>
	import {ajax} from '../../api.js'
	import {ajaxs} from '../../apis.js'
	export default{
		data(){
			return{
				temple:"",
				codes:"",
				second:59,
				Code:true,
				list:""
			}
		},
		methods:{
			reg(){
				var that=this
			
				if(this.temple==""){
				uni.showToast({
				    title: '请输入电话号码',
					icon:"none"
				})
				}else if(this.codes==""){
					uni.showToast({
					    title: '请输入验证码',
						icon:"none"
					})
				}else{
					var header;
												  header = { 
									
									     'content-type': 'application/x-www-form-urlencoded', 
										  'cookie':uni.getStorageSync("sende")//读取cookie
									  };
					uni.request({
					   url:"https://www.uhuoda.com/user/checkSms",
					   method:"post",
					   header:header,
					   data:{
						  smsCode:that.codes,
						   mobile:that.temple
					   },
					   success(res){
						  console.log(res)
						   if(res.data.status=="OK"){
						   		uni.navigateTo({
						   			url:"./forgets?id=1&&phone="+that.temple
						   		})
						   }else{
							   uni.showToast({
							       title: '请输入正确验证码',
							   	icon:"none"
							   })
						   }
						 }
					})
				}
			},
			// 倒计时
			add(){
				var that=this
				if(this.temple.length!=11){
					uni.showToast({
					    title: '请输入正确电话号码',
						icon:"none"
					})
				}else{
				ajax({
					url:"/v1/sms/retrievepwd",
					data:{
						num:this.temple
					},
					success(res){
						
						uni.setStorageSync("sende", res.header["Set-Cookie"])	
					}
				}),
						this.Code=false
			var timer=setInterval(()=>{
				        this.second--
						if(this.second==0){
							clearInterval(timer)
							 this.second=59
							this.Code=true
						}
				   },1000)
				}   
			},
		}
	}
</script>

<style>
	.registered{
		width:345px;
		height:44px;
		border-radius:8px;
		margin-top: 15px;
	}
	input{
		width: 100%;
		height: 100%;
		border-radius:8px;
		background:rgba(245,245,245,1);
		background-image: url(../../static/img/icon_shouji@3x.png);
		background-repeat: no-repeat;
		background-size: 14px,18px;
		background-position: 15px 13px;
		padding-left: 40px;
		box-sizing: border-box;
		font-size: 14px;
	}
	.yan{
		width:85px;
		height:44px;
		background:rgba(4,42,88,1);
		border-radius:8px;
		color: #FFFFFF;
		margin-left: 10px;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 14px;
	}
	button{
		width:345px;
		height:44px;
		background:rgba(4,42,88,1);
		border-radius:8px;
		font-size: 16px;
		margin-top: 30px;
		color: #FFFFFF;
	}
</style>
